# autoregressive family
autoregressionCreator <- function(maxOrder, type) {
  return(
    function(timeSerie){
      options(warn=-1)
      sim <- ar(x=timeSerie, order.max=maxOrder, method=type, demean=FALSE)
      options(warn=1)
      gc()
      return((predict(sim, n.ahead=1)$pred)[1])
    })
}

ARPredict <-autoregressionCreator(1,'ols')